import System
import System.Collections.Generic
import System.Diagnostics
import NUnit.Framework from "nunit.framework"
import ActiveRecord
/*
[TestFixture]
class SampleFixture:
	
	[Test]
	def PassTest():
      pass
	[Test]
	def FailTest():
      pass
*/

[HasMany(Table:"orders")]
[BelongsTo(Table:"sales_reps")]
class Customer(ActiveRecordBase):
   pass
   
[HasOne(Table:"customers")]
[ActiveRecord(TableName:"sales_reps")]
public class SalesRep(ActiveRecordBase):
   pass

[ActiveRecord(TableName:"orders")]
[BelongsTo(Table:"customers", ForeignKey:"customer_id", Lazy:false)]
public class Order(ActiveRecordBase):
   pass

[ActiveRecord(TableName:"post_table")]
[BelongsTo(Table:"blog_table", OrderBy:"created_on, updated_on", Lazy:false, ForeignKey:"parent_id")]
public class Post(ActiveRecordBase):
   pass

public class Company(ActiveRecordBase):
   pass

public class Firm(Company):
   pass

class Test:
   static def TestGenerator():
     #where = SQL.Where("id", 5)
     where = 1
     tableName = "table"
     yield where
     yield tableName

Debug.Listeners.Add(TextWriterTraceListener(Console.Out))

ActiveRecordBase.ConnectionString = "server=localhost; database=sportsfeed; uid=root; pwd=r00t;";
ActiveRecordBase.ConnectionProvider = "MySql";

print "ActiveRecord.Tests"
print ""
/*
ActiveRecordBase.DeleteAll(typeof(Post))

c = Customer()
c["name"] = "Trtavi"
*/
/*
o = Order()
o["customer_id"] = c["id"]
c.DeleteAll(typeof(Customer))
ActiveRecordBase.DeleteAll(typeof(Customer))
c.Save()
o.Save()
print c.ToString()
print "Customer.HasMany.Type: " + c.HasMany.ToString()
print "Customer.HasMany.Keys.Type: " + c.HasMany.Keys.ToString()
print "Customer.HasMany" +  join(c.HasMany, ',')
print Utils.Inspect(c.HasMany)
print "Customer.HasMany.Keys: " +  join(c.HasMany.Keys, ',')
print Utils.Inspect(c.HasMany.Keys)

print c.HasMany["orders"].ToString()
*/
/*
sr = SalesRep()
sr.Save()
c["sales_rep_id"] = sr["id"]
c.Save()
tblSalesReps = c.GetAssociated("sales_reps")
*/
/*
f = Firm()
f["name"] = "37signals"
f.Save()
*/
/*
for x in range(10):
  x *= 2
  yield x
*/

/*
x,y = Test.TestGenerator()
print x
print y
*/
assn1 = HasOneAttribute()
assn2 = HasManyAttribute()
assn3 = HasManyAttribute()
HasOne = Dictionary [of string, AssociationAttribute]()
HasMany = Dictionary [of string, AssociationAttribute]()
HasOne.Add("one", assn1)
HasMany.Add("two", assn2)
HasMany.Add("three", assn3)
iterations = 0
for assnList as Dictionary [of string, AssociationAttribute] in (HasOne, HasMany):
   for name as string in assnList.Keys:
      print "iterating.  assn: ${name}"
      ++iterations

if iterations != 3:
   raise "didn't iterate 3 times"
